home *** CD-ROM | disk | FTP | other *** search
/ Clickx 47 / Clickx 47.iso / assets / software / switchproxy.xpi / chrome / switchproxy.jar / content / import_anon.js < prev    next >
Encoding:
Text File  |  2006-04-11  |  3.4 KB  |  129 lines

  1.  
  2. var num_imported   = 0;
  3. var new_imported  = 0;
  4. var doImport    = true;
  5.  
  6. /*
  7. * Import Proxy List
  8. *  sType is either 'url' or 'file'
  9. *  sPath is the file or URL path
  10. *  oList is the form list to append to
  11. *  sUri is the RDF uri to append to
  12. */
  13. function switchproxy_anon_import(sType, sPath, oList, sUri){
  14.   
  15.     doImport    = true;
  16.   var sProxyList     = "";
  17.   var aProxies    = new Array();
  18.   
  19.   try{
  20.       
  21.     /*
  22.     * Get Proxy List
  23.     */ 
  24.     
  25.       //File
  26.       if(sType == 'file'){
  27.         var oFile = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
  28.           oFile.initWithPath(sPath);
  29.         var oFileStream   = Components.classes["@mozilla.org/network/file-input-stream;1"].createInstance(Components.interfaces.nsIFileInputStream);
  30.           oFileStream.init(oFile, 0x01, 00440, null);
  31.         var oScriptStream   = Components.classes["@mozilla.org/scriptableinputstream;1"].createInstance(Components.interfaces.nsIScriptableInputStream);
  32.           oScriptStream.init(oFileStream);
  33.         
  34.         sProxyList = oScriptStream.read(oScriptStream.available());
  35.       }
  36.       //URL
  37.       else if(sType == 'url'){
  38.       
  39.         var oRequest = new XMLHttpRequest();
  40.           oRequest.open("GET", sPath, false);
  41.           oRequest.send("")
  42.         
  43.         sProxyList = oRequest.responseText;
  44.       }
  45.       //Unknown Type
  46.       else{
  47.         throw "Incorrect type specified";
  48.       }
  49.       
  50.       //Split Proxy List
  51.       aProxies = sProxyList.split("\n");
  52.       
  53.     /*
  54.     * Add to list
  55.     */
  56.       if(oList != null){
  57.         num_imported = 0;
  58.         new_imported = 0;
  59.         for(var i = 0; i < aProxies.length; i++){
  60.           
  61.           if(!doImport) break; //Cancel
  62.         
  63.           aProxies[i] = switchproxy_trim(aProxies[i]);
  64.           
  65.           //Is valid domain & not duplicate
  66.           if(switchproxy_isValidDomain(aProxies[i])){
  67.             num_imported++;
  68.             
  69.             //Not Duplicate
  70.             if(!switchproxy_existsInList(oList, aProxies[i])){
  71.               new_imported++
  72.               switchproxy_anon_addProxyToList(aProxies[i])
  73.             }
  74.           }
  75.           
  76.         }
  77.       }
  78.       
  79.       
  80.     /*
  81.     * Add to RDF
  82.     */
  83.       if(sUri != null && aProxies.length > 0){
  84.           num_imported   = 0;
  85.           new_imported   = 0;
  86.         var oRes       = switchProxy_ds_getResource(sUri)
  87.         
  88.         //Remove existing proxies
  89.         switchProxy_ds_removeProperty(gSProxyRdfNodeUriRoot + "#proxy", oRes);
  90.         
  91.         //Add Imported Proxies
  92.         for(var i = 0; i < aProxies.length; i++){
  93.           
  94.           if(!doImport) break; //Cancel
  95.         
  96.           aProxies[i] = switchproxy_trim(aProxies[i]);
  97.           
  98.           //Is valid domain & not duplicate
  99.           if(switchproxy_isValidDomain(aProxies[i])){
  100.             switchProxy_ds_addProperty(oRes, switchProxy_ds_getResource(gSProxyRdfNodeUriRoot + "#proxy"), aProxies[i], true);
  101.             num_imported++;
  102.             new_imported++
  103.           }
  104.           
  105.         }
  106.       }
  107.   }catch(err){ throw err; }
  108.   
  109. }
  110.  
  111. //Return the number of proxies imported
  112. function switchproxy_anon_getNumImported(){
  113.   return num_imported;
  114. }
  115.  
  116. //Return the number of new proxies imported
  117. function switchproxy_anon_getNewImported(){
  118.   return new_imported;
  119. }
  120.  
  121. //Cancel Import Process
  122. function switchproxy_anon_cancelImport(){
  123.   doImport = false;
  124. }
  125.  
  126. //Does Proxy exist in array from RDF
  127. function switchproxy_anon_doesProxyExist(aList){
  128.   
  129. }